﻿<%@ Page Language="C#" MasterPageFile="~/Masterpages/Default.master" AutoEventWireup="true"
    CodeBehind="ManageWidgets.aspx.cs" Inherits="Blazing.UI.Cms.Admin.ManageWidgets"
    Title="Manage Widgets" %>

<%@ Register Src="../Usercontrols/SelectSite.ascx" TagName="SelectSite" TagPrefix="uc1" %>
<%@ Register Src="../Usercontrols/ChooseSite.ascx" TagName="ChooseSite" TagPrefix="uc2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="System.BusinessObjects.Framework" Namespace="System.BusinessObjects.Controls"
    TagPrefix="cc1" %>
<%@ Register Src="../Usercontrols/Loading.ascx" TagName="Loading" TagPrefix="uc3" %>
<%@ Register Src="../Usercontrols/HiddenSite.ascx" TagName="HiddenSite" TagPrefix="uc4" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h1>
        Manage Widgets</h1>
    <uc2:ChooseSite ID="ChooseSite1" runat="server"></uc2:ChooseSite>
    <hr />
    <ajax:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ObjectDataSource ID="odsRegion" runat="server" DataObjectTypeName="Blazing.BusinessObjects.Widgets.WidgetRegion"
                DeleteMethod="DeleteWidgetRegion" InsertMethod="NewWidgetRegion" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetWidgetRegions" TypeName="Blazing.WebFacade.WidgetController"
                UpdateMethod="UpdateWidgetRegion" OnInserted="odsRegion_Inserted" OnDeleted="odsRegion_Inserted">
            </asp:ObjectDataSource>
            <asp:ObjectDataSource ID="odsWidgetList" runat="server" DataObjectTypeName="Blazing.BusinessObjects.Widgets.Widget"
                DeleteMethod="DeleteWidget" InsertMethod="NewWidget" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetWidgets" TypeName="Blazing.WebFacade.WidgetController" UpdateMethod="UpdateWidget"
                OnInserted="odsWidgetList_Inserted" OnDeleted="odsWidgetList_Inserted">
                <SelectParameters>
                    <asp:SessionParameter Name="siteId" SessionField="siteId" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <cc1:TabContainer ID="TabContainer1" runat="server">
                <cc1:TabPanel ID="TabPanelAddWidget" runat="server" HeaderText="Widgets">
                    <ContentTemplate>
                        <div class="grid">
                            <asp:GridView ID="GridViewWidgets" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,RowStamp,RowState,Site"
                                DataSourceID="odsWidgetList" EmptyDataText="There are no widgets added to this site yet"
                                PageSize="25" Width="95%">
                                <Columns>
                                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                        SortExpression="ID" />
                                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                    <asp:BoundField DataField="Path" HeaderText="Path" SortExpression="Path" />
                                    <asp:TemplateField HeaderText="Default Region">
                                        <EditItemTemplate>
                                            <cc1:BindableDropDownListExtender ID="BindableDropDownListExtender1" runat="server"
                                                AttachTo="DropDownListRegionSelectRegions" BoundValueType="Blazing.BusinessObjects.Widgets.WidgetRegion, Blazing.BusinessObjects"
                                                BoundValue='<%# Bind("Region") %>' />
                                            <asp:DropDownList ID="DropDownListRegionSelectRegions" runat="server" DataSourceID="odsRegion"
                                                DataTextField="Name" DataValueField="ID" AppendDataBoundItems="true">
                                                <asp:ListItem Text="None" Value=""></asp:ListItem>
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <%# Eval("Region.Name") %>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                                </Columns>
                            </asp:GridView>
                        </div>
                        <asp:LinkButton ID="LinkButtonInsertWidget" runat="server">Insert</asp:LinkButton>
                        <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" DynamicServicePath=""
                            Enabled="True" PopupControlID="PanelInsertWidget" PopupDragHandleControlID="PanelAddWidgetTitle"
                            SkinID="Popup1" TargetControlID="LinkButtonInsertWidget">
                        </cc1:ModalPopupExtender>
                        <asp:Panel ID="PanelInsertWidget" runat="server" SkinID="PopupPanel1">
                        <blazing:RoundedPanel ID="rp1" runat="server" width="400px"> 
                            <div class="grid">
                                <div class="gridview">
                                    <asp:Panel ID="PanelAddWidgetTitle" runat="server" CssClass="gridheader">
                                        Add Widget</asp:Panel>
                                    <asp:DetailsView ID="DetailsViewInsertWidget" runat="server" AutoGenerateRows="False"
                                        DataSourceID="odsWidgetList" DefaultMode="Insert">
                                        <Fields>
                                            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                            <asp:BoundField DataField="Path" HeaderText="Path" SortExpression="Path" />
                                            <asp:TemplateField HeaderText="Default Region">
                                                <InsertItemTemplate>
                                                    <cc1:BindableDropDownListExtender ID="BindableDropDownListExtender1" runat="server"
                                                        AttachTo="DropDownList1" BoundValueType="Blazing.BusinessObjects.Widgets.WidgetRegion, Blazing.BusinessObjects"
                                                        BoundValue='<%# Bind("Region") %>' />
                                                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="odsRegion" DataTextField="Name"
                                                        DataValueField="ID" AppendDataBoundItems="true">
                                                        <asp:ListItem Text="None" Value=""></asp:ListItem>
                                                    </asp:DropDownList>
                                                </InsertItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField>
                                                <InsertItemTemplate>
                                                    <uc4:HiddenSite ID="HiddenSite1" runat="server" CurrentSite='<%# Bind("Site") %>' />
                                                </InsertItemTemplate>
                                            </asp:TemplateField>
                                            <asp:CommandField ShowInsertButton="True" />
                                        </Fields>
                                    </asp:DetailsView>
                                </div>
                            </div>
                            </blazing:RoundedPanel>
                        </asp:Panel>
                    </ContentTemplate>
                </cc1:TabPanel>
                <cc1:TabPanel ID="TabPanelAddWidgetRegion" runat="server" HeaderText="Widget Regions">
                    <ContentTemplate>
                        <asp:GridView ID="GridViewWidgetRegions" runat="server" AutoGenerateColumns="False"
                            DataKeyNames="ID,RowState,RowStamp" DataSourceID="odsRegion" EmptyDataText="There are currently no widget regions"
                            Width="95%">
                            <Columns>
                                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" ShowHeader="False"
                                    SortExpression="ID" />
                                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                            </Columns>
                        </asp:GridView>
                        <asp:LinkButton ID="LinkButtonInsertRegion" runat="server">Insert</asp:LinkButton>
                        <ajax:ModalPopupExtender ID="ModalPopupExtender2" runat="server" PopupControlID="PanelInsertWidgetRegion"
                            PopupDragHandleControlID="PanelAddRegionTitle" SkinID="Popup1" TargetControlID="LinkButtonInsertRegion">
                        </ajax:ModalPopupExtender>
                        <asp:Panel ID="PanelInsertWidgetRegion" runat="server" SkinID="PopupPanel1">
                            <div class="PopupPanelInner" style="width: 300px;">
                                <asp:Panel ID="PanelAddRegionTitle" runat="server" CssClass="PopupTitle">
                                    Add Widget Region</asp:Panel>
                                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="odsRegion"
                                    DefaultMode="Insert" Height="50px" Width="125px">
                                    <Fields>
                                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                        <asp:CommandField ShowInsertButton="True" />
                                    </Fields>
                                </asp:DetailsView>
                            </div>
                        </asp:Panel>
                    </ContentTemplate>
                </cc1:TabPanel>
            </cc1:TabContainer></ContentTemplate>
    </ajax:UpdatePanel>
    <br />
    <ajax:UpdateProgress runat="server" ID="update" DisplayAfter="200">
        <ProgressTemplate>
            <uc3:Loading ID="Loading1" runat="server" />
        </ProgressTemplate>
    </ajax:UpdateProgress>
</asp:Content>
